package com.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.Anno.Interceptor;
import com.example.entiys.User;
import com.example.result.Result;
import com.example.service.UserService;
import com.example.utils.smsutil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {
  final
  UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/list")
    @CachePut(cacheNames = "setter#5000",key = "1")
    public List<User> userList(@RequestHeader(required = false) String Truth){
        log.info("来请求了{}",Truth);
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("id",1);
        return userService.list();
    }
    @Autowired
    smsutil smsutil;
    @GetMapping("/sms")
    public void Sms() {
        smsutil.send("1234","13549300143");
    }


    @PostMapping("/login")
    public Result login(@RequestBody User user){
      String token =   userService.login(user);
      return  Result.sucusess(token);

    }

   @Interceptor
    @GetMapping("/test")

    public Result test(){
        return Result.sucusess("成功");
    }

    @GetMapping("/test1")
    public Result test1()
    {
        return Result.sucusess("test1");
    }
}
